﻿using System;
using System.Text.RegularExpressions;

namespace AspNetMvc.Helpers
{
   internal static class DateStringParseHelper
   {
      public static bool Parse(string date, out int year, out int month, out int day)
      {
         Match match = Regex.Match(date, @"^(\d{4})-(\d{1,2})-(\d{1,2})$");

         if (!match.Success)
         {
            year = 0;
            month = 0;
            day = 0;
            return false;
         }

         //According to regular expression, exception can't be raised during converting groups to Int32
         year = Convert.ToInt32(match.Groups[1].Value);
         month = Convert.ToInt32(match.Groups[2].Value);
         day = Convert.ToInt32(match.Groups[3].Value);

         return true;
      }
   }
}